#!/usr/bin/python
"""The player classes."""

__author__ = 'Josh Oosterman'


import pygame

from potv import engine
from potv import geom
from potv import input


class Player(object):
  """The main player character (on foot)."""
  MOVEMENT_SPEED = 3

  def __init__(self, location):
    self.location = location
    image_pattern = 'characters/player/%s.png'
    self.image_left = engine.LoadImage(image_pattern % 'left')
    self.image_right = engine.LoadImage(image_pattern % 'right')
    self.image_up = engine.LoadImage(image_pattern % 'up')
    self.image_down = engine.LoadImage(image_pattern % 'down')
    self.image = self.image_down

  def Step(self):
    motion = geom.Vector(0, 0)
    if input.IsDown(input.PLAYER_LEFT):
      motion.x -= 1
      self.image = self.image_left
    if input.IsDown(input.PLAYER_RIGHT):
      motion.x += 1
      self.image = self.image_right
    if input.IsDown(input.PLAYER_UP):
      motion.y -= 1
      self.image = self.image_up
    if input.IsDown(input.PLAYER_DOWN):
      motion.y += 1
      self.image = self.image_down
    motion = motion.Normalize() * self.MOVEMENT_SPEED
    self.location += motion
    self.level.views[0].Center(self.location)

  def Draw(self, view):
    view.DrawImage(self.image, self.location)
